import { request } from "../../request/index.js";
import regeneratorRuntime from '../../lib/runtime/runtime';
import { login } from "../../utils/asyncWx.js";
Page({
  // 获取用户信息
  async handleGetUserInfo(e){
    try {
      
    // 1 获取用户信息
    const { encrypteData, rawData, iv, signature } = e.detail;
    // 2 获取小程序登录成功后的code
    const {code} = await login();
    const loginParams = { encrypteData, rawData, iv, signature,code }
    // 3 发送请求 获取用户的token
    const res=await request({url:"/users/wxlogin",data:loginParams,method:"post"})
    console.log(res);  
    // 把 token存入缓存中 同时跳转回上一个页面
    // wx.setStorageSync("token", "8961576c9090ef0902c4b89406f8d557");
    wx.setStorageSync("token", token);

    wx.navigateBack({
      delta: 1
    });
    } catch (error) {
      console.log(error);
    }
  }
})